<script setup>
const router = useRouter();
let activeName = ref();
const route = ref([
  { name: "首页", path: "/" },
  {
    name: "展会概况",
    path: "/content/官网-展会概况0",
    type: 0,
    children: [
      {
        name: "展会介绍",
        activeName: "展会概况",
        path: "/content/官网-展会概况0",
        type: 0,
      },
      { name: "往届回顾", path: "/content/官网-展会概况1", type: 1 },
      { name: "组织机构", path: "/content/官网-展会概况2", type: 2 },
      { name: "展品范围", path: "/content/官网-展会概况3", type: 3 },
    ],
  },
  {
    name: "展商中心",
    path: "/content/官网-展商中心0",
    type: 0,
    children: [
      { name: "为何参展", path: "/content/官网-展商中心0", type: 0 },
      { name: "展位图", path: "/content/官网-展商中心1", type: 1 },
    ],
  },
  {
    name: "观众观展",
    path: "/content/官网-观众观展0",
    type: 0,
    children: [
      { name: "为何观展", path: "/content/官网-观众观展0", type: 0 },
      { name: "现场回顾", path: "/content/官网-观众观展1", type: 1 },
      { name: "观展指南", path: "/content/官网-观众观展2", type: 2 },
      { name: "海外组团", path: "/content/官网-观众观展3", type: 3 },
    ],
  },
  {
    name: "新闻中心",
    path: "https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg2NjUzMjc2Mw==&action=getalbum&album_id=2883559164252536832&scene=126#wechat_redirect",
  },
  { name: "同期活动", path: "/activity" },
  {
    name: "联系我们",
    path: "/content/官网-联系我们0",
    type: 0,
    children: [
      { name: "联系电话", path: "/content/官网-联系我们0", type: 0 },
      { name: "交通指南", path: "/content/官网-联系我们1", type: 1 },
    ],
  },
  { name: "合作媒体", path: "/media" },
]);
let isArrow = useState("isArrow");
const changeIsArrow = (flag) => (isArrow.value = flag);
const goUrl = ({ path, name, type }) => {
  if (path.indexOf("http") > -1) {
    window.open(path);
  } else {
    router.push({
      path,
      query: { type },
    });
    activeName.value = name;
    window.sessionStorage.setItem("activeName", name);
  }
};
let showSubMenu = ref();
const handleMouseover = (index) => {
  showSubMenu.value = index;
};
const handleMousemove = () => {
  showSubMenu.value = "null";
};
onMounted(() => {
  activeName.value = window.sessionStorage.getItem("activeName") || "首页";
});
</script>

<template>
  <div @click="changeIsArrow(false)">
    <div class="web">
      <div class="nav">
        <div class="flex">
          <div class="nav-logo">
            <img src="@/assets/images/logo.png" alt="" />
          </div>
          <ul class="menu">
            <li
              v-for="(item, index) in route"
              :class="item.name == activeName ? 'active' : ''"
              @click="goUrl(item)"
              @mouseover="handleMouseover(index)"
            >
              <span>{{ item.name }}</span>
              <Transition>
                <ul
                  v-if="item.children && showSubMenu == index"
                  class="sub-menu"
                  :class="showSubMenu == index ? 'show' : ''"
                  @mouseleave.stop="handleMousemove"
                >
                  <li v-for="items in item.children" @click.stop="goUrl(items)">
                    <span>{{ items.name }}</span>
                  </li>
                </ul>
              </Transition>
            </li>
            <div class="qr-box">
              <div class="qr-icon">
                <img src="@/assets/images/2.png" alt="" />
                <div class="qr">
                  <img src="@/assets/images/footer2.png" alt="" />
                </div>
              </div>
              <div class="qr-icon">
                <img src="@/assets/images/3.png" alt="" />
                <div class="qr">
                  <img src="@/assets/images/douyin.jpg" alt="" />
                </div>
              </div>
              <div class="qr-icon">
                <img src="@/assets/images/4.png" alt="" />
                <div class="qr">
                  <img src="@/assets/images/footer1.png" alt="" />
                </div>
              </div>
            </div>
          </ul>
        </div>
      </div>
    </div>
    <div class="mobiel">
      <div class="nav">
        <div class="nav-logo">
          <img src="@/assets/images/logo.png" alt="" />
          <img
            class="arrow hide"
            :class="!isArrow ? 'show' : ''"
            @click.stop="changeIsArrow(true)"
            src="@/assets/images/menu.png"
            alt=""
          />
        </div>
        <Transition>
          <ul class="menu" v-if="isArrow" :class="isArrow ? 'show' : ''">
            <li
              v-for="item in route"
              :class="item.name == activeName ? 'active' : ''"
              @click="goUrl(item), changeIsArrow(false)"
            >
              <span>{{ item.name }}</span>
              <ul v-if="item.children" class="sub-menu">
                <li
                  v-for="items in item.children"
                  :class="items.name == activeName ? 'active' : ''"
                  @click.stop="goUrl(items), changeIsArrow(false)"
                >
                  <span>{{ items.name }}</span>
                </li>
              </ul>
            </li>
          </ul>
        </Transition>
      </div>
    </div>
  </div>
</template>

<style scoped>
.nav {
  position: fixed;
  background-color: rgba(0, 0, 0, 0.5);
  top: 0;
  left: 0;
  z-index: 99;
  width: 100%;
  padding: 15px 9%;
  cursor: pointer;
}
.flex {
  display: flex;
  align-items: center;
}
.nav .nav-logo {
  margin-left: 1vw;
  box-sizing: border-box;
}
.web .nav-logo img {
  width: 14.896vw;
}
.nav .menu {
  display: flex;
  margin-left: 6.979vw;
}
.nav .menu span {
  color: #fff;
  font-size: 1.2vw;
}
.nav .menu .active > span {
  color: #ff6400;
}
.nav ul li {
  font-family: SourceHanSansSC-regular;
  margin-right: 1.563vw;
  position: relative;
  padding-bottom: 0.563vw;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.nav ul li:hover {
  border-color: #ff6400;
}
li {
  list-style: none;
}
.sub-menu {
  display: none;
  width: 14.375vw;
  position: absolute;
  padding: 0.521vw 0;
  margin-top: 2.1vw;
  background-color: rgba(0, 0, 0, 0.5);
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
  z-index: 999;
}
.sub-menu li {
  padding-left: 1.042vw;
  color: #333;
  margin-left: 1.042vw;
  padding: 0.521vw 0;
  border-bottom: 1px solid #fff !important;
}
.sub-menu li:last-child {
  border: none !important;
}
.sub-menu > li:hover span {
  color: #ff6400;
}
.mobiel {
  display: none;
}
.show {
  display: block;
}
.qr-box {
  display: flex;
  align-items: center;
}

.qr-icon {
  width: 2vw;
  margin-right: 2vw;
  position: relative;
  cursor: pointer;
}

.qr-icon img {
  width: 100%;
}

.qr {
  display: none;
  width: 8vw;
  position: absolute;
  margin-top: 1.5vw;
  left: -2.5vw;
}

.qr-icon:hover .qr {
  display: block;
}

@media (max-width: 768px) {
  .web {
    display: none;
  }
  .mobiel {
    display: block;
  }
  .nav {
    width: 100%;
    padding: 5px;
  }
  .nav ul li {
    margin-right: 0;
    border: none;
  }
  .mobiel ul {
    padding-left: 2.667vw;
  }
  .mobiel .sub-menu {
    display: block;
    width: 100%;
    position: relative;
    background-color: transparent;
    margin: 0;
    box-shadow: none;
  }
  .mobiel .sub-menu li {
    height: auto;
    line-height: 1.2;
  }
  .mobiel .nav {
    display: block;
    height: 10.667vw;
  }
  .mobiel .nav .nav-logo {
    margin-left: 0;
    display: flex;
    justify-content: space-between;
  }

  .arrow {
    margin-right: 4.667vw;
  }
  .close {
    height: 5vw !important;
    z-index: 99;
    position: absolute;
    right: 64vw;
  }
  .mobiel .nav .nav-logo img {
    height: 7vw;
    margin-top: 2vw;
  }
  .mobiel .menu {
    display: none;
    background-color: #fff;
    padding: 0 20px;
    position: fixed;
    right: 0;
    height: 100vh;
    margin-left: 0;
    top: 0;
    line-height: 2;
    z-index: 999;
  }
  .mobiel .menu li span {
    font-size: 18px;
    color: #999;
  }
  .hide {
    display: none;
  }
  .show {
    display: block !important;
  }
}
</style>
